import { defHttp } from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  downOrder = '/waybill/wlhyWaybill/downOrder',
  list = '/waybill/wlhyWaybill/list',
  revoke = '/waybill/wlhyWaybill/revoke',
  revokeBatch = '/waybill/wlhyWaybill/revokeBatch',
  completeDelete = '/waybill/wlhyWaybill/completeDelete',
  completeDeleteBatch = '/waybill/wlhyWaybill/completeDeleteBatch',
  save='/waybill/wlhyWaybill/add',
  edit='/waybill/wlhyWaybill/edit',
  deleteOne = '/waybill/wlhyWaybill/delete',
  loadCargo = '/waybill-api/waybill/wlhyWaybill/loadCargo',
  deleteBatch = '/waybill/wlhyWaybill/deleteBatch',
  importExcel = '/waybill/wlhyWaybill/importExcel',
  exportXls = '/waybill/wlhyWaybill/exportXls',
}

/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;

/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });


/**
 * 装货
 * @param params
 * @param handleSuccess
 */
export const loadCargo = (params,handleSuccess) => {
  return defHttp.post({url: Api.loadCargo, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 恢复单个
 * @param params
 * @param handleSuccess
 */
export const revokeOne = (params,handleSuccess) => {
  return defHttp.post({url: Api.revoke, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 批量恢复
 * @param params
 * @param handleSuccess
 */
export const revokeBatch = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认恢复',
    content: '是否恢复选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.post({url: Api.revokeBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 彻底删除单个
 * @param params
 * @param handleSuccess
 */
export const completeDeleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.completeDelete, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 批量彻底删除
 * @param params
 * @param handleSuccess
 */
export const completeDeleteBatch = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认彻底删除',
    content: '是否彻底删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.completeDeleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 批量删除
 * @param params
 * @param handleSuccess
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 * @param isUpdate
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
}

/**
 * 下运单
 * @param params
 * @param isUpdate
 */
export const downOrder = (params ) => {
  return defHttp.post({ url: Api.downOrder, params }, { isTransformResponse: false });
}
